package com.hansming.bss.modules.sfc.util;


import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.hansming.bss.modules.sfc.service.CarDatePriceService;
import com.hansming.bss.modules.sfc.entity.CarDatePrice;
/**
 * 用来计算日期之间天数的差值 是不
 * @author chen
 *@Date 2017-10-17
 */
public class TimeUtil {
	
	
	
	public static int Datecalc(String fromDate,String toDate){
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
			int result = 0;
			long to = 0;
		try{
			 to  = df.parse(toDate).getTime();
		}catch(ParseException e){
			e.printStackTrace();
		}
			long from = 0;
		try{
			from  = df.parse(fromDate).getTime();
		}catch(ParseException e){
			e.printStackTrace();
		}
			result =(int) ((to - from)/(1000*60*60*24));
		return result;
	}
	
	
	public static String getweekday(String date) throws ParseException{
		
		String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
		Calendar cal = Calendar.getInstance();
		SimpleDateFormat format = new  SimpleDateFormat("yyyy-MM-dd" );
		Date dt = format.parse(date);
		 cal.setTime(dt);  
	        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;  
	        if (w < 0) {  
	            w = 0;  
	        }  
	        return weekDays[w]; 
	}

	//输出某年某月有多少天
	public static int getDaysByyearAndday(int year,int month){
		Calendar a = Calendar.getInstance();  
        a.set(Calendar.YEAR, year);  
        a.set(Calendar.MONTH, month - 1);  
        a.set(Calendar.DATE, 1);  
        a.roll(Calendar.DATE, -1);  
        int maxDate = a.get(Calendar.DATE);  
        return maxDate;  
	}
	
	
	public static int getDayBeforeDateInThisWeek(Date date){
		Calendar cal = Calendar.getInstance();
		 cal.setTime(date);  
	        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;  
	        if (w < 0) {  
	            w = 0;  
	        }  
	        return w;
	}
}
